import { expect } from 'chai';
import {replaceEnvVar, masking} from '../src/util'


describe('masking function', () => {

    it('should mask the password in http url', () => {
        const input = Error('http://username:password@example.com');
        const expectedOutput = 'http://username@example.com';
        expect(masking(input.message)).to.equal(expectedOutput);
    });

    it('should mask the password in https url', () => {
        const input = new Error('https://username:password@example.com');
        const expectedOutput = 'Error: https://username@example.com';
        expect(masking(input)).to.equal(expectedOutput);
    });

});

describe('replaceEnvVar', () => {
    it('should replace environment variables in git tag input', () => {
        // Mock process.env
        const originalEnv = process.env;
        process.env = { ...originalEnv, TEST_ENV_VAR: 'test-value' };

        expect(replaceEnvVar('${TEST_ENV_VAR}_2024')).to.equal('test-value_2024');

        process.env = originalEnv;
    });
    it('should return the input string if no environment variables are found', () => {
        const result = replaceEnvVar('1.0.0');
        expect(result).to.equal('1.0.0');
    });

});
